/*
This file is part of buco.  
Copyright (c) 2012 Christopher Pawelzik <christopher@cpawelzik.com>

Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php 
*/ 
package buco.integrity.classes;

import java.util.HashSet;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import buco.core.api.SemanticConstraint;

public class HasClass extends SemanticConstraint {
	private String name; 
	private HashSet<String> methods; 
	
	public HasClass() { 
		methods = new HashSet<String>(); 
	}

	@Override
	protected void deserialize(JSONObject jsonObject) throws Exception {
		this.name = jsonObject.get("name").toString();		
		
		if(jsonObject.get("methods") != null) {
			JSONArray arr = (JSONArray) jsonObject.get("methods"); 
			for(int i=0; i < arr.size(); i++) { 
				methods.add(arr.get(i).toString()); 
			}
		}
	}
	
	public boolean hasMethod(String method) { 
		return methods.contains(method);
	}

	public String getName() { 
		return name; 
	}
	
	public boolean satisfies(RequireClass requireClass) { 
		return name.equals(requireClass.getName()); 
	}
}
